package fr.efrei.tradesys.hibernate.beans;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "APPUSER")
public class AppUser
{

	private String			login;
	private String			password;
	private String			firstname;
	private String			lastname;
	private String			mail;
	private Boolean			admin;
	private Boolean			enabled;
	private Currency		favoriteCurrency;
	private Set<Owned>	owned	= new HashSet<Owned>();

	public AppUser()
	{
	}

	public AppUser(String login, String password, String firstname,
			String lastname, String mail, Boolean admin, Boolean enabled)
	{
		this.login = login;
		this.password = password;
		this.firstname = firstname;
		this.lastname = lastname;
		this.mail = mail;
		this.admin = admin;
		this.enabled = enabled;
	}

	public AppUser(String login, String password, String firstname,
			String lastname, String mail, Boolean admin, Boolean enabled,
			Currency favoriteCurrency, Set<Owned> owned)
	{
		this.login = login;
		this.password = password;
		this.firstname = firstname;
		this.lastname = lastname;
		this.mail = mail;
		this.admin = admin;
		this.enabled = enabled;
		this.favoriteCurrency = favoriteCurrency;
		this.owned = owned;
	}

	@Id
	@Column(name = "LOGIN", unique = true, nullable = false, length = 50)
	public String getLogin()
	{
		return login;
	}

	public void setLogin(String login)
	{
		this.login = login;
	}

	@Column(name = "PASSWORD", nullable = false, length = 50)
	public String getPassword()
	{
		return password;
	}

	public void setPassword(String password)
	{
		this.password = password;
	}

	@Column(name = "FIRSTNAME", nullable = false, length = 50)
	public String getFirstname()
	{
		return firstname;
	}

	public void setFirstname(String firstname)
	{
		this.firstname = firstname;
	}

	@Column(name = "LASTNAME", nullable = false, length = 50)
	public String getLastname()
	{
		return lastname;
	}

	public void setLastname(String lastname)
	{
		this.lastname = lastname;
	}

	@Column(name = "MAIL", nullable = false, length = 50)
	public String getMail()
	{
		return mail;
	}

	public void setMail(String mail)
	{
		this.mail = mail;
	}

	@Column(name = "ADMIN", nullable = false)
	public Boolean getAdmin()
	{
		return admin;
	}

	public void setAdmin(Boolean admin)
	{
		this.admin = admin;
	}

	@Column(name = "ENABLED", nullable = false)
	public Boolean getEnabled()
	{
		return enabled;
	}

	public void setEnabled(Boolean enabled)
	{
		this.enabled = enabled;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "CODE", nullable = false)
	public Currency getFavoriteCurrency()
	{
		return favoriteCurrency;
	}

	public void setFavoriteCurrency(Currency favoriteCurrency)
	{
		this.favoriteCurrency = favoriteCurrency;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "appUser")
	public Set<Owned> getOwned()
	{
		return owned;
	}

	public void setOwned(Set<Owned> owned)
	{
		this.owned = owned;
	}

}
